type GameObject = Phaser.GameObjects.Image | Phaser.GameObjects.Text;

const Position = (scene: Phaser.Scene, GameObject: GameObject) => {
  const log = (x: number, y: number) => {
    const floor = (n: number) => Math.floor(n * 100) / 100;
    console.log('x , y:>> ', floor(x), ',', floor(y));
  };

  GameObject.setInteractive();
  scene.input.setDraggable(GameObject);

  scene.input.keyboard.on('keydown', (e: any) => {
    if (e.key.includes('Up')) GameObject.y -= 1;
    if (e.key.includes('Down')) GameObject.y += 1;
    if (e.key.includes('Right')) GameObject.x += 1;
    if (e.key.includes('Left')) GameObject.x -= 1;

    log(GameObject.x, GameObject.y);
  });

  GameObject.on('drag', (e: any) => {
    GameObject.x = e.x;
    GameObject.y = e.worldY;
    log(e.x, e.y);
  });
};

export default Position;
